#ifndef USB_TRANSFER_H
#define USB_TRANSFER_H

#include "Nano100Series.h"
#include "Common.h"

#define USBD_VID        0x0416
#define USBD_PID        0x50A1

/* Define EP maximum packet size */
#define EP0_MAX_PKT_SIZE    32
#define EP1_MAX_PKT_SIZE    EP0_MAX_PKT_SIZE
#define EP2_MAX_PKT_SIZE    64
#define EP3_MAX_PKT_SIZE    64
#define EP4_MAX_PKT_SIZE    64
#define EP5_MAX_PKT_SIZE    64
#define EP6_MAX_PKT_SIZE    64
#define EP7_MAX_PKT_SIZE    64

/* Define the buffer address */
#define SETUP_BUF_BASE      0
#define SETUP_BUF_LEN       8
#define EP0_BUF_BASE        (SETUP_BUF_BASE + SETUP_BUF_LEN)
#define EP0_BUF_LEN         EP0_MAX_PKT_SIZE
#define EP1_BUF_BASE        (SETUP_BUF_BASE + SETUP_BUF_LEN)
#define EP1_BUF_LEN         EP1_MAX_PKT_SIZE
#define EP2_BUF_BASE        (EP1_BUF_BASE + EP1_BUF_LEN)
#define EP2_BUF_LEN         EP2_MAX_PKT_SIZE
#define EP3_BUF_BASE        (EP2_BUF_BASE + EP2_BUF_LEN)
#define EP3_BUF_LEN         EP3_MAX_PKT_SIZE
#define EP4_BUF_BASE        (EP3_BUF_BASE + EP3_BUF_LEN)
#define EP4_BUF_LEN         EP4_MAX_PKT_SIZE
#define EP5_BUF_BASE        (EP4_BUF_BASE + EP4_BUF_LEN)
#define EP5_BUF_LEN         EP5_MAX_PKT_SIZE
#define EP6_BUF_BASE        (EP5_BUF_BASE + EP5_BUF_LEN)
#define EP6_BUF_LEN         EP6_MAX_PKT_SIZE
#define EP7_BUF_BASE        (EP6_BUF_BASE + EP6_BUF_LEN)
#define EP7_BUF_LEN         EP7_MAX_PKT_SIZE

/* Define the interrupt In EP number */
#define BULK_IN_EP_NUM_1	0x01
#define BULK_OUT_EP_NUM_1   0x01
#define BULK_IN_EP_NUM_2    0x02
#define BULK_OUT_EP_NUM_2   0x02
#define BULK_IN_EP_NUM_3    0x03
#define BULK_OUT_EP_NUM_3   0x03

/* Define Descriptor information */
#define USBD_SELF_POWERED               0
#define USBD_REMOTE_WAKEUP              0
#define USBD_MAX_POWER                  50  /* The unit is in 2mA. ex: 50 * 2mA = 100mA */

extern int usb_interface_alt;

void UsbTransferInit(void);
void UsbTransferStart(void);
void UsbTransferHandleEvent(void);
void UsbTransferHandleSensorUpdate(void);

#endif
